<?php

namespace App\Http\Controllers\Admin;

use EasyWeChat\Factory;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class WeChatController extends Controller
{
    public function __construct()
    {
        $config = [
            'app_id' => 'wxf266cbed27421ecf',
            'secret' => 'a744bd3e2a46f082630a10a66e1edb7d',
            'token'  => 'dinghui',
            'response_type' => 'array',

            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/wechat.log',
            ],
        ];

        $this->app = Factory::officialAccount($config);


    }

    public function index()
    {

    }


    public function menu()
    {
        return view('admin/wechat/menu');
    }


    public function menuadd(Request $request)
    {

        if ($request->isMethod('post')){
            $buttons = [
                [
                    "type" => "click",
                    "name" => "我的二维码",
                    "url"  => "V1000_MYCODE"
                ],
                [
                    "name"       => "微官网",
                    "sub_button" => [
                        [
                            "type" => "view",
                            "name" => "搜索",
                            "url"  => "http://www.soso.com/"
                        ],
                        [
                            "type" => "view",
                            "name" => "视频",
                            "url"  => "http://v.qq.com/"
                        ],
                        [
                            "type" => "click",
                            "name" => "赞一下我们",
                            "key" => "V1001_GOOD"
                        ],
                    ],
                ],
            ];
            $this->app->menu->create($buttons);
        }
    }
}
